﻿#ifndef __SIG_MEASURE_H__
#define __SIG_MEASURE_H__


#include "timer.h"
#include <stdbool.h>


extern uint16_t freq, duty;


/**
 * @brief 求待测信号频率
 * @note 建议在调用完SigMeasureGetFreq、SigMeasureGetPeriod和SigMeasureGetDuty后
 *       调用SigMeasureClear清除freq和duty
 * @return 频率 Hz
 */
__STATIC_INLINE float SigMeasureGetFreq(void)
{
    return (float)COUNT_FREQ / freq;
}

/**
 * @brief 求待测信号周期
 * @note 建议在调用完SigMeasureGetFreq、SigMeasureGetPeriod和SigMeasureGetDuty后
 *       调用SigMeasureClear清除freq和duty
 * @return 周期 ms
 */
__STATIC_INLINE float SigMeasureGetPeriod(void)
{
    return 1000.0f / SigMeasureGetFreq();
}

/**
 * @brief 求待测信号占空比
 * @note 建议在调用完SigMeasureGetFreq、SigMeasureGetPeriod和SigMeasureGetDuty后
 *       调用SigMeasureClear清除freq和duty
 * @return 占空比 %
 */
__STATIC_INLINE float SigMeasureGetDuty(void)
{
    return (float)duty * 100.0f / freq;
}

/**
 * @brief 清零freq和duty
 */
__STATIC_INLINE void SigMeasureClear(void)
{
    freq = 0;
    duty = 0;
}


bool SigMeasure_GetRising(void);


#endif // !__SIG_MEASURE_H__
